
import { Toast } from "antd-mobile"
import { reqgetgoodsinfo,reqcartadd} from "../../http/api"//State
const initState = {
    getgoodsinfo: {}

}
//action type 
const TYPES = {
    DETAIL_CHANGE_GETGOODSINFO:"DETAIL_CHANGE_GETGOODSINFO"

}
//reducer
const reducer = (state = initState, action) => {
    switch (action.type) {
        case TYPES.DETAIL_CHANGE_GETGOODSINFO:
            return {
                ...state,
                getgoodsinfo: action.getgoodsinfo
            }
        default:
            return state;
    }
}
//action creator
export const actions = {
    changeInfo: (getgoodsinfo) => ({ type: TYPES.DETAIL_CHANGE_GETGOODSINFO, getgoodsinfo }),
    // 请求getgoodsinfo
    getList: (id) => (dispatch, getState) => {
        reqgetgoodsinfo({id}).then(res => {
            dispatch(actions.changeInfo(res.data.list[0]))
        })
    },
    addShop:(goodsid)=>()=>{
        let uid=JSON.parse(sessionStorage.getItem('userInfo')).uid;
        reqcartadd({uid,num:1,type:1,goodsid}).then(res=>{
            Toast.show({
                content:res.data.msg
            })
        })
    }
}

//selector导出数据给组件

//导出
export default reducer;